<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
  xmlns:s="http://jboss.org/schema/seam/taglib"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:a4j="http://richfaces.org/a4j"
  xmlns:rich="http://richfaces.org/rich"
  xmlns:zanata="http://java.sun.com/jsf/composite/zanata"
  template="../WEB-INF/template/template.xhtml">

<ui:define name="page_title">
  #{msgs['jsf.Groups']} - #{versionGroupHome.instance.name}
</ui:define>

<ui:define name="center_content">
<script type="text/javascript">
  //<![CDATA[
  jQuery(function () {
    crossroads.ignoreState = true /* Make sure every url modification gets parsed */
    crossroads.addRoute(':pre*:/version-group/view/{slug}/languages/:lang:',
      function (pre, slug, lang) {
        zanata.tabs.activate(jQuery('#languages_tab'));
        var clickEle = jQuery('a.' + lang);
        if (lang && clickEle.length != 0) {
          updateActiveRow(clickEle)
          toggleColumn('languages')
          reloadLocale(lang)
        }
      });

    crossroads.addRoute(':pre*:/version-group/view/{slug}/projects/{proj}/{ver}',
      function (pre, slug, proj, ver) {
        zanata.tabs.activate(jQuery('#projects_tab'));
        var clickEle = jQuery('#' + jqSelector(proj + "[" + ver + "]") + " a")
        if (clickEle.length != 0) {
          updateActiveRow(clickEle);
          toggleColumn('projects');
          reloadVersion(proj, ver)
        }
      });

    crossroads.addRoute(':pre*:/version-group/view/{slug}/settings/:setting:',
      function (pre, slug, setting) {
        zanata.tabs.activate(jQuery('#settings_tab'));
        setting = setting || 'general';
        setting =
          validateTab("#settings-" + setting + '_tab', setting, 'general');
        zanata.tabs.activate(jQuery('#settings-' + jqSelector(setting) +
          "_tab"))
      });

    crossroads.addRoute(':pre*:/version-group/view/{slug}/:section:',
      function (pre, slug, section) {
        section = section || 'languages'
        section = validateTab('#' + section + "_tab", section, "languages");
        zanata.tabs.activate(jQuery('#' + section + "_tab"))
      });

    renderStatistics();
  })
  //]]>
</script>

<a4j:jsFunction name="reloadLocale" status="languageTab-projectsLoader"
  onbegin="clearHTML('#{rich:clientId('languages-project_list')}');clearHTML('#{rich:clientId('language-label')}');zanata.loader.activate('#languagesTab-language-label-loader')"
  oncomplete="zanata.loader.deactivate('#languagesTab-language-label-loader')"
  render="languages-project_list, language-label, languageTabVersionFilter-pager, languageTabVersionFilter-page-info, languageTabVersionFilterBottom-pager, languageTabVersionFilterBottom-page-info">
  <a4j:param name="val1" assignTo="#{versionGroupHomeAction.selectedLocaleId}"/>
</a4j:jsFunction>

<a4j:jsFunction name="reloadVersion" status="projectsTab-languagesLoader"
  onbegin="clearHTML('#{rich:clientId('projects-language_list')}');clearHTML('#{rich:clientId('project-label')}');zanata.loader.activate('#projectsTab-project-label-loader')"
  oncomplete="zanata.loader.deactivate('#projectsTab-project-label-loader')"
  render="projects-language_list, project-label, projectTabLanguageFilter-pager, projectTabLanguageFilter-page-info, projectTabLanguageFilterBottom-pager, projectTabLanguageFilterBottom-page-info"
  action="#{versionGroupHomeAction.setSelectedVersionSlug(projSlug, verSlug)}">
  <a4j:param name="val1" assignTo="#{projSlug}"/>
  <a4j:param name="val2" assignTo="#{verSlug}"/>
</a4j:jsFunction>

<a4j:jsFunction name="refreshStatistics" status="statistic-loader"
  action="#{versionGroupHomeAction.resetPageData}"
  render="overall_statistic,languages-language_form,languages-project_list,language-label,projects-project_form,projects-language_list,project-label,languages-size,projects-size"/>

<a4j:jsFunction name="renderStatistics" status="statistic-loader"
  render="overall_statistic, languages-language_form, projects-project_form"
  action="#{versionGroupHomeAction.setPageRendered(true)}"
  oncomplete="updateStateFromUrl()"/>

<div class="g">
  <div class="g__item w--1-m w--3-8-l w--1-3 l--push-bottom-half">
    <p class="txt--meta l--push-all-0">
      <s:link view="/version-group/home.xhtml" propagation="none">
        #{msgs['jsf.Groups']}
      </s:link>
    </p>

    <s:div styleClass="media l--push-bottom-half" id="group-info">
      <div class="media__body">
        <h1 class="l--push-all-0">
          #{versionGroupHome.instance.name}
        </h1>

        <p class="txt--understated">
          #{versionGroupHome.instance.description}
        </p>
      </div>
    </s:div>
    <s:div id="overall_statistic" styleClass="progress-bar__expander">
      <s:fragment rendered="#{versionGroupHomeAction.pageRendered}">
        <p class="d--top l--pad-top-half txt--mini">
          #{msgs['jsf.TotalSourceContains']}
          <strong>#{versionGroupHomeAction.overallStatistic.total}
            words</strong>
        </p>
        <ul class="g g--fit">
          <li class="g__item">
            <span class="stats--large txt--state-success">
              <span class="stats__figure">
                #{statisticBar.formatPercentage(versionGroupHomeAction.overallStatistic.percentTranslated)}%
              </span>
              <span class="stats__unit txt--lowercase">
                #{msgs['jsf.stats.Translated']}
              </span>
            </span>
          </li>
          <li class="g__item">
            <span class="stats--large">
              <span class="stats__figure">
                #{statisticBar.formatHours(versionGroupHomeAction.overallStatistic.remainingHours)}
              </span>
              <span class="stats__unit">
                #{msgs['jsf.stats.TotalHoursRemaining']}
              </span>
            </span>
          </li>
        </ul>
        <div class="l--push-v-1">
          <zanata:statistic
            value="#{versionGroupHomeAction.overallStatistic}"
            type="large"/>
        </div>
      </s:fragment>

      <a4j:status name="statistic-loader">
        <f:facet name="start">
          <zanata:loader type="loader--large"/>
        </f:facet>
      </a4j:status>
    </s:div>
  </div>


  <div class="g__item w--1-m w--5-8-l w--2-3">
    <div class="tabs--lined js-tabs">
      <ul class="tabs__nav js-tabs-nav">
        <li>
          <a id="languages_tab"
            href="#{request.contextPath}/version-group/view/#{versionGroupHomeAction.slug}/languages"
            class="js-url-mod" data-content="#languages">
            <i class="i i--language"></i>
              <span class="is-hidden--s i__text--right">
                #{msgs['jsf.Languages']}
              </span>
            <s:span styleClass="txt--neutral" id="languages-size">
              #{versionGroupHomeAction.activeLocales.size}
            </s:span>
          </a>
        </li>
        <li>
          <a id="projects_tab"
            href="#{request.contextPath}/version-group/view/#{versionGroupHomeAction.slug}/projects"
            class="js-url-mod" data-content="#projects">
            <i class="i i--project"></i>
              <span class="is-hidden--s i__text--right">
                #{msgs['jsf.Projects']}
              </span>
            <s:span styleClass="txt--neutral" id="projects-size">
              #{versionGroupHomeAction.getProjectIterations().size}
            </s:span>
          </a>
        </li>
        <li>
          <a id="maintainers_tab"
            href="#{request.contextPath}/version-group/view/#{versionGroupHomeAction.slug}/maintainers"
            class="js-url-mod" data-content="#maintainers">
            <i class="i i--users"></i>
              <span class="is-hidden--s i__text--right">
                #{msgs['jsf.Maintainers']}
              </span>
            <s:span styleClass="txt--neutral" id="maintainers-size">
              #{versionGroupHome.instance.maintainers.size}
            </s:span>
          </a>
        </li>

        <s:fragment
          rendered="#{versionGroupHomeAction.isUserProjectMaintainer()}">
          <li class="tab__end">
            <div
              class="dropdown dropdown--tab dropdown--small dropdown--right dropdown--inline js-dropdown">
              <a class="dropdown__toggle js-dropdown__toggle" href="#"
                title="#{msgs['jsf.tooltip.MoreActions']}"><i
                class="i i--ellipsis"></i></a>
              <ul class="dropdown__content js-dropdown__content"
                role="content"
                aria-labelledby="dropdownContent">
                <li>
                  <s:link view="/version-group/request_to_join.xhtml"
                    styleClass="i__item--right"
                    propagation="none">
                    <f:param name="emailType"
                      value="request_to_join_group"/>
                    <f:param name="versionGroupSlug"
                      value="#{versionGroupHomeAction.slug}"/>
                    <h:outputFormat
                      value="#{msgs['jsf.RequestAddProjectToGroup']}">
                      <f:param value="#{versionGroupHome.instance.name}"/>
                    </h:outputFormat>
                    <i class="i i--project i__item__icon"></i>
                  </s:link>
                </li>
              </ul>
            </div>
          </li>
        </s:fragment>

        <s:fragment
          rendered="#{s:hasPermission(versionGroupHome.instance, 'update')}">
          <li class="tab__end">
            <a id="settings_tab"
              href="#{request.contextPath}/version-group/view/#{versionGroupHomeAction.slug}/settings"
              class="js-url-mod" data-content="#settings">
                <span class="is-hidden--s i__text--left">
                  #{msgs['jsf.Settings']}
                </span>
              <i class="i i--settings"></i>
            </a>
          </li>
        </s:fragment>
      </ul>

      <ul class="tabs__content panels__container js-tabs-content l--push-top-1">
        <li id="languages">
          <ui:include
            src="../WEB-INF/layout/version-group/languages-tab.xhtml">
          </ui:include>
        </li>

        <li id="projects">
          <ui:include
            src="../WEB-INF/layout/version-group/projects-tab.xhtml"/>
        </li>

        <li id="maintainers">
          <zanata:maintainers-tab
            listSize="#{versionGroupHome.instanceMaintainers.size}"
            filterActionBean="#{versionGroupHome.maintainerFilter}"
            settingsUrl="#settings-maintainers"
            PermissionToUpdate="#{s:hasPermission(versionGroupHome.instance, 'update')}"/>
        </li>

        <s:fragment
          rendered="#{s:hasPermission(versionGroupHome.instance, 'update')}">
          <li id="settings">
            <ui:include
              src="../WEB-INF/layout/version-group/settings-tab.xhtml"/>
          </li>
        </s:fragment>
      </ul>
    </div>
  </div>
</div>
</ui:define>

</ui:composition>
